package com.mdd.maduoduo.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.mdd.maduoduo.R;
import com.mdd.maduoduo.entity.ShareCodeEntity;
import com.mdd.maduoduo.utils.CommonAdapter;
import com.mdd.maduoduo.utils.CommonViewHolder;

public class ShareCodeAdapter extends CommonAdapter<ShareCodeEntity.DataDTO.RecordsDTO> {

    private ClickDeleteListener listener;

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_share_code;
    }

    public void setListener(ClickDeleteListener listener) {
        this.listener = listener;
    }

    @Override
    protected void bindData(@NonNull CommonViewHolder holder, ShareCodeEntity.DataDTO.RecordsDTO item, int position) {
        TextView tvRole = holder.getView(R.id.tvRole);
        TextView tvCode = holder.getView(R.id.tvCode);
        TextView tvTime = holder.getView(R.id.tvTime);
        ImageView ivDelete = holder.getView(R.id.ivDelete);

        tvRole.setText(item.role);
        tvCode.setText(item.pickupSharedCode);
        tvTime.setText(item.createTime);

        ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.delete(item);
            }
        });
    }

    public interface ClickDeleteListener{
        void delete(ShareCodeEntity.DataDTO.RecordsDTO data);
    }
}
